package com.zengqingfa.juc.n3;

import lombok.extern.slf4j.Slf4j;

import static java.lang.Thread.sleep;

/**
 * @author zengqingfa
 * @className TestJoin
 * @description
 * @create 2021/6/7 22:24
 */
@Slf4j(topic = "c.TestJoin")
public class TestJoin {

    static int r = 0;

    public static void main(String[] args) throws Exception {
        test1();
    }

    /**
     * 22:29:13:738 [main] c.TestJoin - 开始
     * 22:29:13:781 [Thread-0] c.TestJoin - 开始
     * 22:29:13:783 [Thread-0] c.TestJoin - 结束
     * 22:29:13:783 [main] c.TestJoin - 结果为:10
     * 22:29:13:785 [main] c.TestJoin - 结束
     */
    private static void test1() throws Exception {
        log.debug("开始");
        Thread t1 = new Thread(() -> {
            log.debug("开始");
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("结束");
            r = 10;
        });
        t1.start();
        t1.join();
        log.debug("结果为:{}", r);
        log.debug("结束");
    }
}